/**
*  @file 
*  @ingroup common
**/

#ifdef __cplusplus
extern "C"
{
#endif

/*******************************/

//#define MODENAMESTRLEN 128
#define PLATFORMNAMESTRLEN 64
#define TIMESTRLEN 64
#define UNITSTRLEN 32

#define MAXWPTS 128


//*************************************************************************

#define NUMSCIDAT	11
#define SCIDATNAMESTRLEN 32

#ifdef NEED_SCINAMES
static char scidatnames[NUMSCIDAT][SCIDATNAMESTRLEN] = 
{
	"Humidity",
	"Air Temp",
	"Water Temp",
	"Windspeed",
	"Wind Angle",
	"Air Pressure",
	"Salinity",
	"Fluorescence",
	"Bathymetry",
	"Current Speed",
	"Current Angle"
};
#endif

typedef enum{
	SCIDAT_HUMIDITY,
	SCIDAT_AIRTEMP,
	SCIDAT_WATERTEMP,
	SCIDAT_WINDSPEED,
	SCIDAT_WINDANGLE,
	SCIDAT_AIRPRESSURE,
	SCIDAT_SALINITY,
	SCIDAT_FLUORESCENCE,
	SCIDAT_BATHYMETRY,
	SCIDAT_CURRENTSPEED,
	SCIDAT_CURRENTANGLE
}SCIDATTYPE;


//*************************************************************************

#define NUMENGDAT 3
#define ENGDATNAMESTRLEN 32

#ifdef NEED_ENGNAMES
static char engdatnames[NUMENGDAT][ENGDATNAMESTRLEN] = 
{
	"Main Battery",
	"Rudder Percent",
	"Throttle Percent",
};
#endif

typedef enum{
	ENGDAT_MAINBATTERY = 0,
	ENGDAT_RUDDER,
	ENGDAT_THROTTLE,
}ENGDATTYPE;


#include <gps.h>
typedef struct gps_fix_t GPS_DATA;
typedef struct gps_fix_t *pGPS_DATA;

//struct gps_fix_t {
//    double time;	/* Time of update, seconds since Unix epoch */
//    int    mode;	/* Mode of fix */
//#define MODE_NOT_SEEN	0	/* mode update not seen yet */
//#define MODE_NO_FIX	1	/* none */
//#define MODE_2D  	2	/* good for latitude/longitude */
//#define MODE_3D  	3	/* good for altitude/climb too */
//    double ept;		/* Expected time uncertainty */
//    double latitude;	/* Latitude in degrees (valid if mode >= 2) */
//    double longitude;	/* Longitude in degrees (valid if mode >= 2) */
//    double eph;  	/* Horizontal position uncertainty, meters */
//    double altitude;	/* Altitude in meters (valid if mode == 3) */
//    double epv;  	/* Vertical position uncertainty, meters */
//    double track;	/* Course made good (relative to true north) */
//    double epd;		/* Track uncertainty, degrees */
//    double speed;	/* Speed over ground, meters/sec */
//    double eps;		/* Speed uncertainty, meters/sec */
//    double climb;       /* Vertical speed, meters/sec */
//    double epc;		/* Vertical speed uncertainty */
//};



//*************************************************************************
typedef struct
{
	double dValue;
	
	char   sUnits[UNITSTRLEN];

	char   sTime[TIMESTRLEN];	// date string

	int nTime; 	// seconds since epoch
	
	POSITION position;
	
}SCI_DBL;


//*************************************************************************
typedef struct
{
	double dValue;
	
	char sUnits[UNITSTRLEN];

	char sTime[TIMESTRLEN];	// date string

	int nTime; 	// seconds since epoch
	
	
}ENG_DBL;


/*******************************/
typedef struct
{
	//platform identification
	int    nPlatformID;
	char   sPlatformName[PLATFORMNAMESTRLEN];
	int    nPlatformType;
	char   sPlatformTypeName[PLATTYPESTRLEN];

	//basic engineering telemetry
	int    nPlatformMode;
	char   sPlatformModeName[MODENAMESTRLEN];
	
	int	 nCommsLatency;

	char   sTime[TIMESTRLEN];	// date string
	int nTime; 	// seconds since epoch
	
	double dLonDeg;
	double dLatDeg;
	double dAltMeters;       

	double dSpeed_mps;			// groundspeed (GPS / net motion)
	double dWaterspeed_mps;		// speed of boat relative to water
   
	double dDirectionDeg;		// direction of groundspeed (GPS / net motion)

	double dHdgDeg;           
	double dPitchDeg;           
	double dRollDeg;           

//	double dBattVolts;

	//additional engineering telemetry
	ENG_DBL dMainBattery_V;
	ENG_DBL dRudderCommand;
	ENG_DBL dThrottleCommand;


	//science telemetry
	SCI_DBL dHumidPct;
	SCI_DBL dAirTempDegC;
	SCI_DBL dWaterTempDegC;
   
	SCI_DBL dWindSpeed_mps;
	SCI_DBL dWindAngleDeg;   
	SCI_DBL dAirPress_mbar;
   
	SCI_DBL dSalinity_psu;
	SCI_DBL dFluorescence_V;	

	SCI_DBL dBathymetry;

	SCI_DBL dCurrentSpeedMPS;
	SCI_DBL dCurrentAngleDeg;

	// waypoints
	int	nWaypointCount;
	int	nCurrWaypt;
	WAYPT CurrWpt;
	WAYPT Waypoints[MAXWPTS];
	
	GPS_DATA gpsdata;
	
	SCI_DBL last_waypoint;
	SCI_DBL current_waypoint;

	//SONDE data
	SCI_DBL tempC;
	SCI_DBL speCond;
	SCI_DBL o2Sat;
	SCI_DBL o2Chrg;
	SCI_DBL pH;
		
}STATUS;

enum COMMSLATENCY{
	COMMS_LATENCY_GOOD=0,
	COMMS_LATENCY_SLOW,
	COMMS_LATENCY_BAD
};

/*******************************/
STATUS  status_InitStatus();
void    status_PrintStatus(STATUS s);
int     status_compareStatus(STATUS s1, STATUS s2);

int status_compareEngStatus(STATUS s1, STATUS s2);

SCI_DBL status_InitSciDbl();
void    status_PrintSciDbl(SCI_DBL d);
int status_compareSciDbl(SCI_DBL s1, SCI_DBL s2);

ENG_DBL status_InitEngDbl();
void    status_PrintEngDbl(ENG_DBL d);
int status_compareEngDbl(ENG_DBL s1, ENG_DBL s2);

void status_PrintGPSData(GPS_DATA d);


//STATUS  status_ReadFile(char *filespec);
//void    status_WriteFile(char *filespec,STATUS s);

POSITION status_PositionFromStatus(STATUS s);
WAYPT status_WaypointFromStatus(STATUS s);
int status_VerifyStatus(STATUS s);
void status_SetTimeString(char *s,int size,struct tm *time);

#ifdef __cplusplus
}
#endif
